package top.yzhao.trackdatasystem.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import top.yzhao.trackdatasystem.VO.ResultVO;
import top.yzhao.trackdatasystem.VO.TableVO;
import top.yzhao.trackdatasystem.form.TrackDataForm;
import top.yzhao.trackdatasystem.model.TrackData;
import top.yzhao.trackdatasystem.service.TrackDataService;

import java.util.List;

/**
 * User: zhaoyang
 * Date: 2020/3/13
 * Time: 1:00
 * Description: 轨检数据展示的api
 */
@RestController
public class TrackDataController {
    @Autowired
    private TrackDataService trackDataService;

    /**
     * 首页表格需要
     * @return
     */
    @PostMapping("/getLeastTrackData")
    public ResultVO<List> getLeastTrackData(){
        ResultVO<List> res = new ResultVO<>();
        List<String[]> td = trackDataService.getLeastTrackData();
        res.setData(td);
        if(td.size()!=0){
            res.setCode(200);
            res.setMsg("获取数据成功");
        }else {
            res.setCode(100);
            res.setMsg("获取数据失败");
        }
        return res;
    }


    @PostMapping("/getTrackData")
    public ResultVO<TableVO> getTrackData(@RequestBody TrackDataForm trackDataForm){
        ResultVO<TableVO> res = new ResultVO<>();
        TableVO<List> tb = new TableVO<>();

        List<TrackData> tdfList = trackDataService.getTrackData(trackDataForm);
        int total = trackDataService.getTotalTrackData(trackDataForm);
        tb.setData(tdfList);
        tb.setTotal(total);

        res.setData(tb);
        if(tdfList.size()!=0){
            res.setCode(200);
            res.setMsg("数据查询成功");
        }else {
            res.setCode(100);
            res.setMsg("获取数据失败");
        }
        return res;
    }

    @PostMapping("/getTrackDataLine")
    public ResultVO<String[]> getTrackDataLine(@RequestBody TrackDataForm trackDataForm){
        ResultVO<String[]> res = new ResultVO<>();

        String[] trackdd = trackDataService.getTrackDataLine(trackDataForm);

        res.setData(trackdd);
        if(trackdd.length!=0){
            res.setCode(200);
            res.setMsg("数据查询成功");
        }else {
            res.setCode(100);
            res.setMsg("获取数据失败");
        }
        return res;
    }

    @PostMapping("/getTrackDataLineFExcel")
    public ResultVO<String[]> getTrackDataLineFExcel(@RequestBody TrackDataForm trackDataForm, int od){
        ResultVO<String[]> res = new ResultVO<>();

        String[] trackdd = trackDataService.getTrackDataLineFExcel(trackDataForm,od);

        res.setData(trackdd);
        if(trackdd.length!=0){
            res.setCode(200);
            res.setMsg("数据查询成功");
        }else {
            res.setCode(100);
            res.setMsg("获取数据失败");
        }
        return res;
    }

}
